package com.czk.gulimall.order.web;

import com.alipay.api.AlipayApiException;
import com.czk.gulimall.order.config.AlipayTemplate;
import com.czk.gulimall.order.service.OrderService;
import com.czk.gulimall.order.vo.PayVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @Author:ChenZhangKun
 * @Date: 2022/5/29 16:09
 */
@Controller
public class PayWebController {
    @Autowired
    private AlipayTemplate alipayTemplate;
    @Autowired
    private OrderService orderService;

    /**
     * 支付宝支付页
     *
     * @param orderSn
     * @return
     * @throws AlipayApiException
     */
    @GetMapping("/payOrder")
    public String payOrder(@RequestParam("orderSn") String orderSn) throws AlipayApiException {
        PayVo payVo = orderService.getOrderPay(orderSn);
        // 返回的是一个html页面代码，将此页面直接返回个浏览器
        String pay = alipayTemplate.pay(payVo);
        System.out.println(pay);
        // 会跳转到质保支付页
        return pay;
    }
}
